/**
 * @class   wosh::gui::SheetAdmin
 * @brief   
 *
 *
 ****************************************************************************
 * @version $Id: SheetAdmin.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_SheetAdmin_H__
 #define __WOSH_Gui_SheetAdmin_H__

 #include <framework/gui/kiosk/KioskSheet.h>
 #include <framework/gui/widgets/wCore_PropertiesProvider.h>
 #include "ui_SheetAdmin.h"

using namespace wosh;
namespace wosh {
 namespace gui {

class SheetAdmin : public KioskSheetGeneric  {

	Q_OBJECT

	public:
		/**
		 * @brief  Empty constructor.
		 */
		SheetAdmin() : KioskSheetGeneric() {
			this->m_ui = new Ui::SheetAdmin();
			this->m_ui->setupUi(this);
			setName("SheetAdmin");
			setContext("KiosK::Sheet::Admin");
			
			setWindowTitle("KiosK Administration");
			this->getWidgetURI().setName( Utilities::format("SheetAdministration#%ld", Utilities::randomLong()) );
			this->getTargetURI().fromString( ":KioskManager" );

			this->propMapperSecurity = new PropertiesMapper(this);
			this->propMapperSecurity->getMap().insert("asd1", this->m_ui->sliderSecurityStandByAuto);
			this->propMapperSecurity->getMap().insert("asd2", this->m_ui->chkSecurityLogoutAuto);

			this->propMapperStyle = new PropertiesMapper(this);
//			this->propMapperStyle->getMap().insert("asd", this->m_ui->sliderSecurityStandBy);

			connect(this->m_ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(listWidget_itemSelectionChanged()) );

			connect(this->m_ui->wUpBarSecurity, SIGNAL(updateClicked()), this, SLOT(refreshSecurity()));
			connect(this->m_ui->wUpBarStyle, SIGNAL(updateClicked()), this, SLOT(refreshStyle()));

		 }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~SheetAdmin() {
			delete this->propMapperStyle;
			delete this->propMapperSecurity;
			delete this->m_ui;
		 }

	public:

		virtual void refreshAll() {
			refreshSecurity();
			refreshStyle();
		 }

		virtual void busMessage( const Message& message, const Bus* ) {
			if ( message.isEmpty() ) return;
			if ( !message.getContent()->isResponse() ) return;
			if ( !isMessageForMeOrFromTarget(message) )
				return;
			const wosh::Response* response = message.getContent()->asResponse();

			//promptMethodResponse( response, true );

			if ( this->propMapperSecurity->evalResponse(response) )
				this->m_ui->wUpBarSecurity->sayReady();

			if ( this->propMapperStyle->evalResponse(response) )
				this->m_ui->wUpBarStyle->sayReady();

		 }

	protected slots:
		void listWidget_itemSelectionChanged() {
			this->m_ui->stackedWidget->setCurrentIndex( this->m_ui->listWidget->currentRow() );
		 }

		void refreshSecurity() {
			List* dlProps = this->propMapperSecurity->createKeysList();
			Request* request_method = new Request( _METHOD_GetProperties, dlProps );
			postMessageForTarget( new Message(request_method) );
			this->m_ui->wUpBarSecurity->sayRetrieving();
		 }
		void refreshStyle() {
			List* dlProps = this->propMapperStyle->createKeysList();
			Request* request_method = new Request( _METHOD_GetProperties, dlProps );
			postMessageForTarget( new Message(request_method) );
			this->m_ui->wUpBarStyle->sayRetrieving();
		 }


	protected:
		PropertiesMapper* propMapperSecurity;
		PropertiesMapper* propMapperStyle;

	private:
		Ui::SheetAdmin *m_ui;


}; // class def

  }; // namespace gui
}; // namespace wosh

#endif //__WOSH_Gui_SheetAdmin_H__

